package com.mai4j.maiadmin.misc;

import com.littlenb.snowflake.sequence.IdGenerator;
import com.littlenb.snowflake.support.MillisIdGeneratorFactory;

/**
 * Created by 席有芳 on 2021/3/26.
 * Id 生成工具
 *
 * @author 席有芳
 */
public class Id {

    private final IdGenerator generator;

    /**
     * 构造一个ID生成器
     *
     * @param workerId workerId
     */
    public Id(long workerId) {
        this.generator = new MillisIdGeneratorFactory(1609430400000L).create(workerId);
    }


    /**
     * @return id
     */
    public String parse(long id) {
        return generator.parse(id);
    }

    /**
     * @return id
     */
    public long next() {
        return generator.nextId();
    }

    /**
     * @return id
     */
    public String id() {
        return String.valueOf(next());
    }
}
